/*
    Project:        Home Power Control
    File:           HPCValue.cpp
    Author:         christian@karunamusic.at
    Date:           01.2015
    Description:    A value class of all types for use with the sensors.
 */

#include <QDateTime>
#include "Logger/HPCLogger.h"
#include "HPCValue.h"

HPCValue::HPCValue()
    : QObject(), m_Var()
{
    m_TimeStamp = QDateTime::currentDateTime().toTime_t();
}

HPCValue::HPCValue( const QVariant & v )
    : QObject(), m_Var(v)
{
    m_TimeStamp = QDateTime::currentDateTime().toTime_t();
}

HPCValue::HPCValue( const HPCValue & v ) : QObject()
{
    *this = v;
}

HPCValue::~HPCValue()
{
}

void HPCValue::V( const QVariant& v )
{
    if ( m_Var != v )
    {
        m_Var = v;
        m_TimeStamp = QDateTime::currentDateTime().toTime_t();
        LOG(trace, "value changed: " << m_Var.toBool());
        emit changed( *this );
    }
}

HPCValue& HPCValue::operator = ( const HPCValue& v )
{
    if ( m_Var != v.m_Var )
    {
        m_Var = v.m_Var;
        LOG(trace, "value changed: " << m_Var.toBool());
        emit changed( *this );
    }
    m_TimeStamp = v.m_TimeStamp;

    return *this;
}
